package com.googlecode.garbagecan.dbtest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

public class TestBatch {
	public static void main(String[] args) throws Exception {
		TestBatch t = new TestBatch();
		t.test();
	}
	
	private void test() throws Exception {
		Connection conn = getConnection();
		String sql = "INSERT INTO RESOURCE_ATTRIBUTES(RESOURCE_NAME,RESOURCE_TYPE,ATTRIBUTE_NAME,ATTRIBUTE_TYPE,ATTRIBUTE_VALUE_STR,ATTRIBUTE_VALUE_NUM,TIME_STAMP,TIME_STAMP_GMT,CLUSTER_NAME)VALUES(?,?,?,?,?,?,?,?,?)";
		//netra03,host,cpuf,Numeric,null,26.0,2008-05-07 04:00:00.0,1210147200000,lsf702
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setObject(1, "netra03");
		ps.setObject(2, "host");
		ps.setObject(3, "cpuf");
		ps.setObject(4, "Numeric");
		ps.setObject(5, null);
		ps.setObject(6, "26.0");
		ps.setObject(7, new Timestamp(1210147200000l));
		ps.setObject(8, Long.valueOf(1210147200000l));
		ps.setObject(9, "lsf702");
		ps.addBatch();
		ps.executeBatch();
		ps.clearBatch();
		ps.close();
		conn.close();
	}
	
	private Connection getConnection() throws SQLException,
			ClassNotFoundException {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		String url = "jdbc:oracle:thin:@172.17.1.119:1521:orcl";
		//String url = "jdbc:oracle:thin:@perf01:1521:orcl";
		DriverManager.setLoginTimeout(10);
		Connection conn = DriverManager.getConnection(url, "lizhang", "lizhang");
		return conn;
	}
}
